package dp

func rob(nums []int) int {
	// 如果两间相邻的房屋在同一晚上被小偷闯入，系统会自动报警
	if len(nums) == 1 {
		return nums[0]
	}
	if len(nums) == 2 {
		return max(nums[0], nums[1])
	}
	dp := make([]int, len(nums))
	dp[0] = nums[0]
	dp[1] = max(nums[0], nums[1])
	for i := 2; i < len(nums); i++ {
		dp[i] = max(dp[i - 1], dp[i - 2] + nums[i])
	}
	return dp[len(nums) - 1]
}